package com.jhc.soft.controller;

import cn.hutool.core.lang.UUID;
import com.jhc.soft.dto.LoginDto;
import com.jhc.soft.dto.ValidDto;
import com.jhc.soft.entity.User;
import com.jhc.soft.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author: zfm
 * @Date: 2021/11/11 09:10
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserService iUserService;

    public final static String KEY = "8baaf9b1cfe74a48be7219265fc8debb";


    @GetMapping("/test")

    public Object test(int id) {
        return iUserService.getById(id);
    }



    @GetMapping("/login")
    public Object login(String username, String password) {
        return iUserService.login(username, password);
    }

    @GetMapping("/zhuce")
    public Object zhuce(String username, String password, String name) {
        return iUserService.zhuce(username,password, name);
    }

    @GetMapping("/news")
    public Object getNews(String type) {
        String url= "http://v.juhe.cn/toutiao/index?type=" + type +"&key=" + KEY;
        RestTemplate restTemplate = new RestTemplate();
        String data = restTemplate.getForObject(url,String.class);
        return data;
    }

    @GetMapping("/weather")
    public Object getWeather() {

        String url = "http://apis.juhe.cn/simpleWeather/query?city=金华&key=fe0410ffd868ce251ecc76e72a1ec758";
        RestTemplate restTemplate = new RestTemplate();
        String obj = restTemplate.getForObject(url, String.class);
        return obj;
    }



    //    校验用户是否绑定
    @PostMapping("/valid")
    public Object valid(@RequestBody ValidDto dto) {
        return iUserService.valid(dto);
    }
    //    微信小程序登陆
    @PostMapping("/login/min")
    public Object loginByMin(@RequestBody LoginDto dto){
        return iUserService.loginByMin(dto);
    }
}